import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class ControlPanel extends JPanel {

  /**
   * Create the panel
   */
  public ControlPanel(RABID frame) {
    super();
    setOpaque(false);
    setMinimumSize(new Dimension(650, 150));
    setPreferredSize(new Dimension(650, 150));
    setMaximumSize(new Dimension(650, 150));
    setLayout(null);

    guiFrame = frame;
    userInputField = new JTextField();
    userInputField.setOpaque(false);
    userInputField.setBorder(null);
    userInputField.setBounds(185, 53, 280, 22);
    add(userInputField);

    queryButton = new JButton();
    queryButton.setToolTipText("Query");
    queryButton.setPressedIcon(new ImageIcon(
        ControlPanel.class.getResource("skin/button_query_pressed.png")));
    queryButton.setRolloverIcon(new ImageIcon(
        ControlPanel.class.getResource("skin/button_query_over.png")));
    queryButton.setFocusPainted(false);
    queryButton.setContentAreaFilled(false);
    queryButton.setBorderPainted(false);
    queryButton.setIcon(new ImageIcon(
        ControlPanel.class.getResource("skin/button_query.png")));
    queryButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        queryButtonClickListener();
      }
    });
    queryButton.setBounds(481, 25, 75, 75);
    add(queryButton);

    final JLabel backGroundLabel = new JLabel();
    add(backGroundLabel);
    backGroundLabel.setIcon(new ImageIcon(
        ControlPanel.class.getResource("skin/control_background.png")));
    backGroundLabel.setBounds(0, 0, 650, 150);
  }

  public String getUserInput() {
    return userInputField.getText();
  }

  public void setUserInput(String in) {
    userInputField.setText(in);
  }

  private void queryButtonClickListener() {
    String userInput = getUserInput();
    guiFrame.doQuery(userInput);
  }

  private RABID guiFrame;

  private JButton queryButton;

  private JTextField userInputField;

}
